from django.db import models

# Create your models here.
from apps.usermanager.models import User, Urls


# 产品
class Product(models.Model):
    name = models.CharField(max_length=10, verbose_name="名称")


# 故障类型
class FaultClasses(models.Model):
    name = models.CharField(max_length=20)
    error_num = models.CharField(max_length=10, default="")
    detail = models.CharField(max_length=50)


# 产品故障
class ProductFault(models.Model):
    product = models.ForeignKey(Product, on_delete=models.CASCADE, verbose_name='产品')
    name = models.CharField(max_length=20, default=None)
    classes = models.ForeignKey(FaultClasses, on_delete=models.CASCADE, verbose_name='故障', null=True)


# 语言
class Lanuage(models.Model):
    name = models.CharField(max_length=10)
    in_chinese = models.CharField(max_length=10)


# 应用场景
class Scene(models.Model):
    name = models.CharField(max_length=10)


# 类型
class DemoClasses(models.Model):
    title = models.CharField(max_length=10, default="")
    parent = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, )
    is_tail = models.BooleanField(default=False, verbose_name="子节点")


# 案例
class Demo(models.Model):
    #url = models.ForeignKey(Urls,on_delete=models.DO_NOTHING,null=True)
    # demo_id = models.UUIDField(verbose_name="档案号")
    title = models.CharField(max_length=10, verbose_name="标题")
    # index = models.ForeignKey(IndexChar, verbose_name="关键字")
    # lanuage = models.ForeignKey(Lanuage, on_delete=models.DO_NOTHING, verbose_name="语种")
    creat_time = models.DateTimeField(verbose_name="创建时间")
    last_update = models.DateTimeField(verbose_name='最后更新时间')
    remarks = models.CharField(max_length=100, verbose_name='摘要')
    # link = models.CharField(max_length=10, verbose_name="关联文档", null=True)
    scene = models.ForeignKey(Scene, on_delete=models.DO_NOTHING, verbose_name="场景")
    content = models.TextField()
    author = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    classes = models.ForeignKey(DemoClasses, on_delete=models.DO_NOTHING, verbose_name="类型", null=True)
    download_time = models.IntegerField(verbose_name="下载次数", default=0)
    read_time = models.IntegerField(verbose_name="浏览次数", default=0)
    clock = models.BooleanField(default=False, verbose_name="上锁")
    supreme = models.BooleanField(default=False, verbose_name="精品")
    collect_time = models.IntegerField(verbose_name="收藏次数",null=True)
    product = models.CharField(max_length=20,verbose_name="产品",null=True)


# 关键字
class IndexChar(models.Model):
    name = models.CharField(max_length=20, verbose_name="关键字")
    demo = models.ForeignKey(Demo, on_delete=models.CASCADE, verbose_name="案例")


# 案例文件
class DemoFile(models.Model):
    demo_id = models.ForeignKey(Demo, on_delete=models.SET_NULL, null=True)
    files = models.FileField(upload_to=None, max_length=100)
    title = models.CharField(max_length=20, null=True)


# 收藏
class Collect(models.Model):
    user_id = models.ForeignKey(User, on_delete=models.CASCADE)
    demo_id = models.ForeignKey(Demo, on_delete=models.CASCADE)


# 案例内容
class DemoContent(models.Model):
    demo_id = models.ForeignKey(Demo, on_delete=models.CASCADE)
    title = models.CharField(max_length=12, verbose_name="标题")
    content = models.CharField(max_length=100, verbose_name="文本内容")
